<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
            overflow: hidden;
        }
        .sub{
            width: 50px;
            height: 50px;
            background-color: #000;
            margin: 75px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
 
    
    // onmouseover onmouseout的问题
    // 描述:  给父元素绑定事件,鼠标滑过子元素时,也会父元素的触发移入移出事件  
    // 解决方法: 使用 onmouseenter onmouseleave 替代  onmouseover onmouseout


    // 事件对象的属性 (适用于onmouseenter onmouseleave   onmouseover onmouseout)
    // fromElement    事件触发时,从哪个元素来
    // toElement      事件触发时,从到个元素去

    var box = document.getElementsByClassName("box")[0];
    var sub = document.getElementsByClassName("sub")[0];

    box.onmouseenter = function(e){
        console.log("鼠标划入box",e.fromElement,e.toElement);
    }

    box.onmouseleave = function(e){
        console.log("鼠标划出box",e.fromElement,e.toElement);
    }







</script>
</html>